package com.ikan.positionserver.util;

import com.google.common.collect.Lists;
import com.ikan.positionserver.dto.TenantHostDto;
import com.ikan.positionserver.entity.TenantHost;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
@UtilityClass
public class TenantHostConverter {
    public static final TenantHostDto convert2Dto(TenantHost tenantHost) {
        if (tenantHost == null) {
            return null;
        }
        TenantHostDto tenantHostDto = new TenantHostDto();
        tenantHostDto.setId(tenantHost.getId());
        tenantHostDto.setUuid(tenantHost.getUuid());
        tenantHostDto.setAppId(tenantHost.getAppId());
        tenantHostDto.setCloudIp(tenantHost.getCloudIp());
        tenantHostDto.setHostIp(tenantHost.getHostIp());
        tenantHostDto.setHostname(tenantHost.getHostname());
        tenantHostDto.setInstanceId(tenantHost.getInstanceId());
        tenantHostDto.setMirrorId(tenantHost.getMirrorId());
        tenantHostDto.setMirrorName(tenantHost.getMirrorName());
        tenantHostDto.setNetwork(tenantHost.getNetwork());
        tenantHostDto.setStatus(tenantHost.getStatus());

        tenantHostDto.setCreateTime(tenantHost.getCreateTime());
        tenantHostDto.setCreator(tenantHost.getCreator());
        tenantHostDto.setUpdateTime(tenantHost.getUpdateTime());
        tenantHostDto.setUpdator(tenantHost.getUpdator());
        return tenantHostDto;
    }

    public static final TenantHost convert(TenantHostDto tenantHostDto) {
        if (tenantHostDto == null) {
            return null;
        }
        TenantHost tenantHost = new TenantHost();
        tenantHost.setId(tenantHostDto.getId());
        tenantHost.setUuid(tenantHostDto.getUuid());
        tenantHost.setAppId(tenantHostDto.getAppId());
        tenantHost.setCloudIp(tenantHostDto.getCloudIp());
        tenantHost.setHostIp(tenantHostDto.getHostIp());
        tenantHost.setHostname(tenantHostDto.getHostname());
        tenantHost.setInstanceId(tenantHostDto.getInstanceId());
        tenantHost.setMirrorId(tenantHostDto.getMirrorId());
        tenantHost.setMirrorName(tenantHostDto.getMirrorName());
        tenantHost.setNetwork(tenantHostDto.getNetwork());
        tenantHost.setStatus(tenantHostDto.getStatus());

        tenantHost.setCreateTime(tenantHostDto.getCreateTime());
        tenantHost.setCreator(tenantHostDto.getCreator());
        tenantHost.setUpdateTime(tenantHostDto.getUpdateTime());
        tenantHost.setUpdator(tenantHostDto.getUpdator());
        return tenantHost;
    }

    public static final List<TenantHostDto> convertList2Dto(List<TenantHost> tenantHostList) {
        if (tenantHostList == null) {
            return null;
        }
        List<TenantHostDto> tenantHostDtoList = Lists.newArrayList();
        for (TenantHost rack : tenantHostList) {
            TenantHostDto tenantHostDto = convert2Dto(rack);
            tenantHostDtoList.add(tenantHostDto);
        }
        return tenantHostDtoList;
    }
}
